<?php

/**
 * 统一返回接口
 * $code: 0:正确, >0:错误
 * $data: 返回数据
 * $msg:  提示
 */
class ApiBack
{
    public static function result($data, $msg, $code)
    {
        $result = [
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ];
        echo json_encode($result);
        exit;
    }

    public static function success($data, $msg="OK", $code =0)
    {
        ApiBack::result($data, $msg, $code);
    }

    public static function error($msg, $code =1)
    {
        ApiBack::result([], $msg, $code);
    }
}